/******************************************************************************
* File description: experimentmethod.qml
* Function: 扩增程序配置
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-09-02
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Item {
    id: root

    /* property 定义开始 */
    // 阶段步骤数据
    property var stageStepData: [{"保温阶段": [[], [], []]}, {"PCR阶段": [[], []]},
        {"保温阶段": [[], [], []]}, {"保温阶段": [[], [], []]}]

    // 信号
    // 当前阶段的最后一个步骤变化
    signal stageLastStepYPosChanged(int curStageIndex, real pos)

    /* property 定义结束 */

    RowLayout {
        id: methodContainer
        anchors.fill: parent
        spacing: 0

        // 左按钮
        Rectangle {
            id: leftBtn
            Layout.preferredWidth: 60
            Layout.fillHeight: true
            color: "#80FF0000"
            border.width: 0

            MouseArea {
                anchors.fill: parent
                onPressed: {
                    var contentX = stageStepContainer.contentX
                    contentX -= 40
                    if(contentX < 0) {
                        contentX = 0
                    }
                    stageStepContainer.contentX = contentX
                }
            }
        }

        // 阶段步骤
        Flickable {
            id: stageStepContainer
            Layout.fillWidth: true
            Layout.fillHeight: true
            interactive: false
            clip: true
            boundsBehavior: Flickable.StopAtBounds
            contentWidth: contentRow.implicitWidth

            Row {
                id: contentRow
                height: methodContainer.height
                spacing: 18

                Repeater {
                    model: root.stageStepData

                    MethodStage {
                        id: stage
                        height: parent.height
                        stageName: Object.keys(modelData)[0]
                        stepData: modelData[Object.keys(modelData)[0]]

                        onLastStepYPosChanged: {
                            root.stageLastStepYPosChanged(index, stage.lastStepYPos)
                        }

                        Connections {
                            target: root

                            // 当前阶段的最后一个步骤变化
                            function onStageLastStepYPosChanged(curStageIndex, pos) {
                                if(index === curStageIndex +1){
                                    stage.firstStepPolygonLeftChanged(pos)
                                }
                            }
                        }
                    }
                }
            }
        }

        // 右按钮
        Rectangle {
            id: rightBtn
            Layout.preferredWidth: 60
            Layout.fillHeight: true
            color: "#80FF0000"
            border.width: 0

            MouseArea {
                anchors.fill: parent
                onPressed: {
                    var contentX = stageStepContainer.contentX
                    contentX += 40
                    if(contentX > stageStepContainer.contentWidth - stageStepContainer.width) {
                        contentX = stageStepContainer.contentWidth - stageStepContainer.width
                    }
                    stageStepContainer.contentX = contentX
                }
            }
        }
    }
}
